package agentspeakeditor.editors.marker;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.texteditor.MarkerUtilities;
import org.xml.sax.SAXParseException;

public class ASLMarkerErrorHandler {

	private final String ERROR_MARKER_ID = "com.example.markers.r.us.coolmarker";

	private IFile file;
	private IDocument document;
	
	public ASLMarkerErrorHandler(IFile inputFile, IDocument document) {
		this.file = inputFile;
		this.document = document;
	}


	public void handleError(String e, boolean isFatal)
	{
	    int lineNumber = 4;
	    int columnNumber = 6;

	    Map map = new HashMap();
	    MarkerUtilities.setLineNumber(map, lineNumber);
	    MarkerUtilities.setMessage(map, e);
	    map.put(IMarker.MESSAGE, e);
	    map.put(IMarker.LOCATION, file.getFullPath().toString());

	    Integer charStart = null;//getCharStart(lineNumber, columnNumber);
	    if (charStart != null)
	        map.put(IMarker.CHAR_START, charStart);

	    Integer charEnd = null;//getCharEnd(lineNumber, columnNumber);
	    if (charEnd != null)
	        map.put(IMarker.CHAR_END, charEnd);

	    map.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
	    try
	    {
	        MarkerUtilities.createMarker(file, map, ERROR_MARKER_ID);
	    }
	    catch (CoreException ee)
	    {
	        ee.printStackTrace();
	    }
	}
	

	public void removeExistingMarkers() throws CoreException {
		file.deleteMarkers(ERROR_MARKER_ID, true, IResource.DEPTH_ZERO);		
	}
}
